import Router from "vue-router"
import store from "store"
import CampaignList from "campaign-list"
import Campaign from "campaign"

import Login from "login"
import App from "app"

export default new Router({
  mode: "history",
  routes: [
    {
      path: "/login",
      component: Login,
    },
    {
      path: "/",
      component: App,
      // beforeEnter: checkLoggedIn,
      children: [
        {
          path: "/",
          redirect: "/spider-list",
        },
        {
          path: "/spider-list",
          component: CampaignList,
        },
        {
          path: "/spider",
          component: Campaign,
        },
        {
          path: "/spider/:id",
          component: Campaign,
        },
      ],
    },
  ],
})

function checkLoggedIn(to, from, next) {
  if(!store.getters.loggedIn) {
    next("/login")
  } else {
    next()
  }
}
